<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.simpleforum.model.ForumApplication" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>板块申请审核 - 极简论坛</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
    <h1>板块申请审核</h1>
    
    <% if (request.getAttribute("error") != null) { %>
    <div class="error-message"><%= request.getAttribute("error") %></div>
    <% } %>
    
    <% if (request.getAttribute("success") != null) { %>
    <div class="success-message"><%= request.getAttribute("success") %></div>
    <% } %>
    
    <% 
        List<ForumApplication> appList = (List<ForumApplication>) request.getAttribute("applications");
        if (appList == null || appList.isEmpty()) { 
    %>
    <p>暂无待审核的申请</p>
    <% } else { %>
    <table class="application-table">
        <thead>
            <tr>
                <th>申请人</th>
                <th>板块名称</th>
                <th>申请理由</th>
                <th>申请时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <% for (ForumApplication app : appList) { %>
            <tr>
                <td>用户ID: <%= app.getApplicantId() %></td>
                <td>
                    <% if (app.getForumId() != null) { %>
                        板块ID: <%= app.getForumId() %>
                    <% } else { %>
                        <strong>申请创建新板块:</strong> <%= app.getForumName() %>
                        <br>
                        <small>描述: <%= app.getForumDescription() %></small>
                    <% } %>
                </td>
                <td><%= app.getReason() %></td>
                <td><%= app.getApplyTime() %></td>
                <td>
                    <form action="ForumApplicationReviewServlet" method="post" style="display: inline;">
                        <input type="hidden" name="applicationId" value="<%= app.getId() %>">
                        <input type="hidden" name="action" value="approve">
                        <textarea name="reviewNotes" placeholder="审核备注" rows="2"></textarea>
                        <button type="submit" class="btn">批准</button>
                    </form>
                    <form action="ForumApplicationReviewServlet" method="post" style="display: inline;">
                        <input type="hidden" name="applicationId" value="<%= app.getId() %>">
                        <input type="hidden" name="action" value="reject">
                        <textarea name="reviewNotes" placeholder="拒绝原因" rows="2"></textarea>
                        <button type="submit" class="btn btn-danger">拒绝</button>
                    </form>
                </td>
            </tr>
            <% } %>
        </tbody>
    </table>
    <% } %>
    
    <p><a href="index.jsp">返回首页</a></p>
</div>
</body>
</html>